package org.yaukie.builder;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;

import java.util.Date;

/**
 *  @Author: yuenbin
 *  @Date :2020/11/13
 * @Time :14:12
 * @Motto: It is better to be clear than to be clever !
 * @Destrib:  写一个调度执行器监听
**/
public class QuartzListener implements JobListener{

	@Override
	public String getName() {
		return new Date().getTime() + "QuartzListener";
	}
	@Override
	public void jobToBeExecuted(JobExecutionContext context) {
	}
	@Override
	public void jobExecutionVetoed(JobExecutionContext context) {
	}
	@Override
	public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
		String jobName = context.getJobDetail().getKey().getName();
		String jobGroupName = context.getJobDetail().getKey().getGroup();
		String triggerName = context.getTrigger().getKey().getName();
		String triggerGroupName = context.getTrigger().getKey().getGroup();
		//一次性任务，执行完之后需要移除
		QuartzManager.removeJob(jobName, jobGroupName, triggerName, triggerGroupName);
	}
}
